package lc.inte;

import java.util.HashMap;
import java.util.Map;

public class Q0102 {
    public boolean CheckPermutation(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        }
        Map<Character, Integer> counts = new HashMap<>(Math.min(128, s1.length()));
        for (int i = 0; i < s1.length(); i++) {
            counts.put(s1.charAt(i), counts.getOrDefault(s1.charAt(i), 0) + 1);
            counts.put(s2.charAt(i), counts.getOrDefault(s2.charAt(i), 0) - 1);
        }
        for (Map.Entry<Character, Integer> entry : counts.entrySet()) {
            if (entry.getValue() != 0) {
                return false;
            }
        }
        return true;
    }
}
